package com.itany.action;

import com.alibaba.fastjson.JSON;
import com.itany.pojo.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 陈华旺
 * @version 1.0
 * @date 2023年11月24日 15:10
 * @Description TODO
 */
@WebServlet("/checkcode")
public class CheckCodeAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String code = req.getParameter("code"); // 页面传递的验证码
        String targetCode = (String) req.getSession().getAttribute("code");
        resp.setContentType("text/json;charset=utf-8");
        if(targetCode.equals(code)){
            AjaxResult result = new AjaxResult("正确",true,null,10001,null);
            resp.getWriter().println(JSON.toJSONString( result ));
        }else{
            AjaxResult result = new AjaxResult("错误",false,null,10002,null);
            resp.getWriter().println(JSON.toJSONString( result ));
        }
    }
}













